package io.gitee.zhangbinhub.acp.boot.ftp

import io.gitee.zhangbinhub.acp.boot.ftp.conf.AcpFtpServerConfiguration
import io.gitee.zhangbinhub.acp.boot.ftp.init.FtpServerInitialization
import io.gitee.zhangbinhub.acp.core.ftp.InitFtpServer
import io.gitee.zhangbinhub.acp.core.ftp.user.UserFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean

/**
 * @author zhang by 21/06/2019
 * @since JDK 11
 */
@AutoConfiguration
@EnableConfigurationProperties(
    AcpFtpServerConfiguration::class
)
class AcpFtpAutoConfiguration {

    @Bean
    @ConditionalOnClass(InitFtpServer::class)
    fun ftpServerInitialization(
        acpFtpServerConfiguration: AcpFtpServerConfiguration,
        @Autowired(required = false)
        userFactoryList: List<UserFactory>?
    ) = FtpServerInitialization(acpFtpServerConfiguration, userFactoryList)
}
